﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QQ.InterviewQuestions.ShiftedArray
{
    internal class ShiftedArray
    {
        public int FindMinIndexPartialSorted(int[] a)
        {
            if (a == null || a.Length <= 0)
            {
                return -1;
            }

            int middle, left, right;
            left = 0;
            right = a.Length - 1;

            while (left <= right)
            {
                middle = (left + right) / 2;
                if (a[middle] < a[left])
                {
                    right = middle;
                }
                else if (a[middle] == a[left])
                {
                    return middle;
                }
                else if (a[middle] > a[left])
                {
                    left = middle;
                }

            }

            return -1;
        }
    }
}
